package com.sheepone.util.enums;

/**
 * @author Miss.杨
 * @description
 * @since 2024/3/2 - 19:59
 */
public enum PressureUnit {
    MPA(PressureUnit.MPA_SCALE),
    ATM(PressureUnit.ATM_SCALE),
    BAR(PressureUnit.BAR_SCALE),
    KPA(PressureUnit.KPA_SCALE),
    HPA(PressureUnit.HPA_SCALE),
    PASCAL(PressureUnit.PASCAL_SCALE);

    private static final double PASCAL_SCALE = 1;
    private static final double HPA_SCALE = 100 * PASCAL_SCALE;
    private static final double KPA_SCALE = 1000 * PASCAL_SCALE;
    private static final double BAR_SCALE = 100000 * PASCAL_SCALE;
    private static final double ATM_SCALE = 101325 * PASCAL_SCALE;
    private static final double MPA_SCALE = 1000000 * PASCAL_SCALE;

    PressureUnit(double scale) {
        this.scale = scale;
    }

    private final double scale;

    public double toPASCAL(double pressure) {
        return pressure * scale;
    }
    public double toHPA(double pressure) {
        return pressure * scale / HPA_SCALE;
    }
    public double toKPA(double pressure) {
        return pressure * scale / KPA_SCALE;
    }
    public double toBAR(double pressure) {
        return pressure * scale / BAR_SCALE;
    }
    public double toATM(double pressure) {
        return pressure * scale / ATM_SCALE;
    }
    public double toMPA(double pressure) {
        return pressure * scale / MPA_SCALE;
    }
    public double convert(double pressure, PressureUnit unit) {
        return switch (unit) {
            case PASCAL -> toPASCAL(pressure);
            case HPA -> toHPA(pressure);
            case KPA -> toKPA(pressure);
            case BAR -> toBAR(pressure);
            case ATM -> toATM(pressure);
            case MPA -> toMPA(pressure);
        };
    }


}
